<template>
    <Select v-model="buildingid" :placeholder="placeholder" clearable v-bind="$attrs" v-on="$listeners" filterable>
        <Option v-for="item in data" :value="item.id" :key="item.id">{{ item.name }}</Option>
    </Select>
</template>

<script>
export default {
    props: {
        //楼宇
        value: {
            type: [String, Number, Object],
            default: ""
        },
        //行政区域id
        orgid: {
            type: [String, Number],
            default: ""
        },
    },
    data() {
        return {
            data: [],
            buildingid: "",
            placeholder: "请选择行政区域",
            selectItem: {}
        }
    },
    watch: {
        orgid: function (val) {
            if (val) {
                this.getInitData()
            } else {
                this.data = []
                this.buildingid = ""
                this.placeholder = "请选择行政区域"
            }
        }
    },
    methods: {
        async getInitData() {
            this.placeholder = "数据加载中..."
            let res = await this.$api.geography.buildingList({
                page: 1,
                rows: 1000,
                orgid: this.orgid
            });
            this.data = res.rows
            this.placeholder = "请选择楼宇"

            this.buildingid = Number.parseInt(this.value)
        },
    },
    created() {
        if (this.orgid) {
            this.getInitData()
        }
    }
}
</script>

<style lang="less" scoped>

</style>
